Visualizing `&`, `|`, and `^`.
The **Bitwise AND** operator returns `1` in each bit position for which the corresponding bits of both operands are `1`. Otherwise, it returns `0`.
5 & 1; // 1 (binary 0101 & 0001 -> 0001)
Binary A:
Binary B:
Result Binary:
Result (Decimal):
The **Bitwise OR** operator returns `1` in each bit position for which the corresponding bits of either or both operands are `1`. Otherwise, it returns `0`.
5 | 1; // 5 (binary 0101 | 0001 -> 0101)
Binary A:
Binary B:
Result Binary:
Result (Decimal):
The **Bitwise XOR** (exclusive OR) operator returns `1` in each bit position for which the corresponding bits of the two operands are different. Otherwise, it returns `0`.
5 ^ 1; // 4 (binary 0101 ^ 0001 -> 0100)
Binary A:
Binary B:
Result Binary:
Result (Decimal):